package com.lemon.cloud.minio;

import com.lemon.cloud.minio.http.OssEndpoint;
import com.lemon.cloud.minio.service.OssTemplate;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author HuangDS
 */
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties({OssProperties.class})
public class OssAutoConfiguration {
    @Bean
    @ConditionalOnMissingBean({OssTemplate.class})
    @ConditionalOnProperty(
            prefix = "oss",
            name = {"enable"},
            havingValue = "true",
            matchIfMissing = true
    )
    public OssTemplate ossTemplate(OssProperties properties) {
        return new OssTemplate(properties);
    }

    @Bean
    @ConditionalOnWebApplication
    @ConditionalOnProperty(
            prefix = "oss",
            name = {"http.enable"},
            havingValue = "true"
    )
    public OssEndpoint ossEndpoint(OssTemplate template) {
        return new OssEndpoint(template);
    }

}
